package main.java.com.NWPU.services;

import main.java.com.NWPU.models.Experiment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExperimentService {

    private final Map<Integer, Experiment> experiments;

    public ExperimentService() {
        this.experiments = new HashMap<>();
    }

    public List<Experiment> getAllExperiments() {
        return new ArrayList<>(experiments.values());
    }

    public Experiment getExperimentById(int id) {
        return experiments.get(id);
    }

    public Experiment createExperiment(Experiment experiment) {
        int id = experiments.size() + 1;
        experiment.setId(id);
        experiments.put(id, experiment);
        return experiment;
    }

    public Experiment updateExperiment(int id, Experiment updatedExperiment) {
        Experiment experiment = experiments.get(id);
        if (experiment != null) {
            experiment.setName(updatedExperiment.getName());
            experiment.setDescription(updatedExperiment.getDescription());
            return experiment;
        }
        return null;
    }

    public void deleteExperiment(int id) {
        experiments.remove(id);
    }
}